﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#if SILVERLIGHT
using System.Windows.Media;
using GameEngineSL.SilverlightCompatibility;
#else
using System.Drawing;
using System.Windows.Forms;
#endif

using GameEngine.Worlds;

namespace GameEngine.Interactors
{
    public abstract class BaseInteractor : IPointerInteractor
    {
        protected World world;

        // Draging
        private bool isDragging;
        private PointF dragStartPosition;
        private MouseButtons dragButton;
        // Minimum distance the pointer must be moved to trigger a drag.
        private const double dragMinDistance = 0.0;

        /// <summary>
        /// BaseInteractor constructor
        /// </summary>
        /// <param name="world">
        /// World to operate on.</param>
        public BaseInteractor(World world)
        {
            this.world = world;
        }

        /// <summary>
        /// The left mouse button has been clicked.
        /// </summary>
        /// <param name="position">
        /// Current position of the pointer.</param>
        /// <param name="button">
        /// Mouse Button which went down.</param>
        public void OnMouseDown(PointF position, MouseButtons button)
        {
            // Turn drag mode on.
            isDragging = true;
            dragButton = button;
            dragStartPosition = position;
        }

        /// <summary>
        /// The pointer is moved (mouse move).
        /// </summary>
        /// <param name="position">
        /// Current position of the  pointer.</param>
        public void OnMouseMove(PointF position)
        {
            if (isDragging)
            {
                // Call dragging
                OnMouseDragging(dragStartPosition, position, dragButton);
            }
        }

        /// <summary>
        /// The pointer is deactivated (mouse up).
        /// </summary>
        /// <param name="position">
        /// Current position of the pointer.</param>
        /// <param name="button">
        /// Mouse Button which went up.</param>
        public void OnMouseUp(PointF position, MouseButtons button)
        {
            if (isDragging)
            {
                OnMouseDragged(dragStartPosition, position, dragButton);
                // Stop dragging
                isDragging = false;
            }
        }

        /// <summary>
        /// The pointer dragging (being moved while button is down).
        /// </summary>
        /// <param name="startPosition">
        /// Position of the pointer where dragging started.</param>
        /// <param name="currentPosition">
        /// Current position of the pointer.</param>
        /// <param name="button">
        /// Mouse Button which is started the drag.</param>
        protected void OnMouseDragging(PointF startPosition, PointF currentPosition, MouseButtons button) { }

        /// <summary>
        /// The pointer is deactivated (mouse up).
        /// </summary>
        /// <param name="startPosition">
        /// Position of the pointer where dragging started.</param>
        /// <param name="endlocation">
        /// Position of the pointer where dragging ended.</param>
        /// <param name="button">
        /// Mouse Button which is started the drag.</param>
        protected void OnMouseDragged(PointF startPosition, PointF endPosition, MouseButtons button) { }
    }
}
